package com.photologics.logic;

import android.app.Dialog;
import android.content.Context;
import android.support.v7.widget.GridLayout;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.photologics.logic.LogicHelper.item;
import com.photologics.main.GiveCoinDialog;
import com.photologics.main.R;

public class RandomItemDialog extends Dialog{
	private ImageView[][] giftBox;
	private GridLayout giftBoxBoard;
	private final Context con;
	
	public RandomItemDialog(Context context) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.random_itme_dialog);
		
		con = context;
		giftBoxBoard = (GridLayout)findViewById(R.id.gift_box_board);
		giftBox = new ImageView[2][3];
		
		for(int i=0 ; i<2 ; i++) {
			for(int j=0 ; j<3 ; j++){
				giftBox[i][j] = new ImageView(context);
				giftBox[i][j].setImageResource(R.drawable.gift_box);
				giftBox[i][j].setPadding(20, 20, 20, 20);
				giftBox[i][j].setOnClickListener(new ImageView.OnClickListener() {
					@Override
					public void onClick(View v) {
						int randomNum = (int)(Math.random()*14);
						GiveCoinDialog dialog;
						
						if(randomNum<7){
							dialog = new GiveCoinDialog(con, item.NONE, 500);
						} else if(randomNum<11){
							dialog = new GiveCoinDialog(con, item.NONE, 1000);
						} else if(randomNum<13){
							dialog = new GiveCoinDialog(con, item.SHOW, 1);
						} else {
							dialog = new GiveCoinDialog(con, item.REMOVE, 1);
						}
						
						dialog.getWindow().clearFlags(
								WindowManager.LayoutParams.FLAG_DIM_BEHIND);
						dialog.show();
						dismiss();
					}
				}); 
				giftBoxBoard.addView(giftBox[i][j]);
			}
		}
	}
}
